//
//  CZVisitorTableViewController.swift
//  WeiBoNew
//
//  Created by 秦川 on 16/5/11.
//  Copyright © 2016年 秦川. All rights reserved.
//

import UIKit

class CZVisitorTableViewController: UITableViewController {
    
    var userLogin = CZUserAccountViewModel.shareUserAccount.islogin
    
    var visitorView: CZVisitorView?
    override func loadView() {
        if userLogin {
            super.loadView()
        }else{
            visitorView = CZVisitorView()
            
            visitorView?.callBackColsure = {[weak self] in
                print("哈哈")
                print(self)
            self?.requestOAuthLogin()
                
                
            }
            view = visitorView
            setUpUI()
        }
        
    }
    
    private func setUpUI(){
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", fontSize: 15, target: self, action: "registerAction")
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", fontSize: 15, target: self, action: "loginAction")
        
    }
    
    @objc private func registerAction(){
        print("registerAction")
        requestOAuthLogin()
    }
    @objc private func loginAction(){
        print("loginAction")
        requestOAuthLogin()
    }
    
    private func requestOAuthLogin(){
        let oauthVC = CZOAuthViewController()
        let nav = UINavigationController(rootViewController: oauthVC)
        presentViewController(nav, animated: true, completion: nil)
    }
    
    
    
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false
        
        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    
}
